home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / makebin.com / MAKEHEX.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-04-16  |  2.0 KB  |  89 lines

  1. {converts intel hex file into TP inline hex format}
  2. {MAKEHEX V1.01  Copyright 1989  Michael Day   as of 16 April 1989}
  3. {all rights reserved}
  4. program makehex;
  5. uses dos;
  6. const MaxSize = 20000;
  7. var fr,fw:file;
  8.     f1,f2:string;
  9.     hcount,ri,wi,wc,result : integer;
  10.     tempr:array[0..MaxSize] of byte;
  11.     tempw:array[0..MaxSize] of byte;
  12.  
  13. function hexnum(H,L:byte):integer;
  14. var temp:integer;
  15. begin
  16.   if H > $39 then
  17.     temp := ((H - 7) shl 4) and $f0
  18.   else
  19.     temp := (H shl 4) and $f0;
  20.   if L > $39 then
  21.     temp := temp + ((L - 7) and $f)
  22.   else
  23.     temp := temp + (L and $f);
  24.   hexnum := temp;
  25. end;
  26.  
  27. begin
  28.   fillchar(fr,sizeof(fr),0);
  29.   fillchar(fw,sizeof(fw),0);
  30.   if paramcount < 2 then
  31.   begin
  32.     writeln('**  Error: Insufficent data given  **');
  33.     writeln('Format is: MAKEHEX INFILE.HEX OUTFILE.PAS');
  34.     halt(1);
  35.   end;
  36.   f1 := ParamStr(1);
  37.   f2 := ParamStr(2);
  38.   writeln('Reading:',f1,' --> Creating:',f2);
  39.  
  40.   assign(fr,f1);
  41.   reset(fr,1);
  42.   if FileSize(fr) > (maxsize) then
  43.   begin
  44.     writeln('Error:',f1,' <- File is too big to convert');
  45.     Halt(3);
  46.   end;
  47.   blockread(fr,tempr,MaxSize,result);
  48.   close(fr);
  49.   assign(fw,f2);
  50.   rewrite(fw,1);
  51.  
  52.   ri := 0;
  53.   wi := 0;
  54.   wc := 0;
  55.   while ri <= result do
  56.   begin
  57.     while (tempr[ri] <> byte(':')) and (ri <= result) do inc(ri);
  58.     if ri <= result then
  59.     begin
  60.       hcount := hexnum(tempr[ri+1],tempr[ri+2]);
  61.       inc(ri,9);
  62.       while (ri <= result) and (hcount > 0) do
  63.       begin
  64.         tempw[wi] := byte('$');
  65.         tempw[wi+1] := tempr[ri];
  66.         tempw[wi+2] := tempr[ri+1];
  67.         tempw[wi+3] := byte(',');
  68.         inc(wi,4);
  69.         inc(ri,2);
  70.         dec(hcount);
  71.         inc(wc);
  72.         if (wc and $f) = 0 then
  73.         begin
  74.           tempw[wi] := 13;
  75.           tempw[wi+1] := 10;
  76.           inc(wi,2);
  77.         end;
  78.       end;
  79.     end;
  80.   end;
  81.   tempw[wi] := 13;
  82.   tempw[wi+1] := 10;
  83.   inc(wi,2);
  84.   blockwrite(fw,tempw,wi,result);
  85.   close(fw);
  86.   writeln('* Done *');
  87. end.
  88.  
  89.